package com.baiytfp.hf.HFDataExchange.action.service;

import com.baiytfp.hf.HFDataExchange.common.model.table.User_role;
import com.baiytfp.hf.baiytfp.common.db.HFPager;
import com.baiytfp.hf.baiytfp.framework.base.BaseService;
import com.baiytfp.hf.baiytfp.hfutils.HFDBHelper;
import com.baiytfp.hf.baiytfp.hfutils.HFMap;
import com.baiytfp.hf.HFDataExchange.action.dao.RoleDAOImpl;
import com.baiytfp.hf.HFDataExchange.action.dao.TagsDAOImpl;
import com.baiytfp.hf.HFDataExchange.common.model.base.HFSysParams;
import com.baiytfp.hf.HFDataExchange.common.model.base.TableName;
import com.baiytfp.hf.HFDataExchange.common.model.table.Role;
import com.baiytfp.hf.HFDataExchange.common.model.table.Tags;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Steven-HF on 2017/5/13.
 */

@Service
public class RoleService extends BaseService {

	@Resource(name= HFSysParams.DB_TYPE + "RoleDAOImpl")
	private RoleDAOImpl roleDAO;


	public RoleService() throws Exception {

	}


	public List<Role> getRoleList(HFPager hfPager)
			throws Exception {

		Map<String, String> map = hfPager.getParams();

		StringBuffer sWhere = new StringBuffer(" where 1 =1 ");
		StringBuffer sql = new StringBuffer("select * from " + TableName.ROLE);

		List<String> params = new ArrayList<String>();

		if (!"".equals(hfPager.getParam("role_name"))) {
			if (sWhere.length() > 0) {
				sWhere.append(" and ");
			}
			sWhere.append(" role_name like ?");
			params.add("%" + HFMap.getIstance().getString(map, "role_name") + "%");
		}

		List<Role> list = HFDBHelper.list_split(sql.toString() + sWhere.toString() + hfPager.getOrderBy(), Role.class, hfPager, params.toArray());

		return list;
	}

	public List<User_role> getHasUserCodeByUserRole(String role_code) throws Exception {
		return roleDAO.getHasUserCodeByUserRole(role_code);
	}

}

